package ru.evga.gwt.lib.common.client.ui.dialog;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;

/**
 * Edit view for CityProxy.
 */
public class ConfirmButtonBar extends Composite
{

    interface Binder extends UiBinder<HTMLPanel, ConfirmButtonBar>
    {
    }

    private static final Binder BINDER = GWT.create(Binder.class);

    public interface Presenter
    {
        void yesClick();
        void noClick();
        void cancelClicked();
    }

    @UiField
    Button m_yes;
    @UiField
    Button m_no;
    @UiField
    Button m_cancel;

    private Presenter m_presenter;

    public ConfirmButtonBar(ConfirmDialog.BUTTON_TYPE type)
    {
        initWidget(BINDER.createAndBindUi(this));
        if(ConfirmDialog.BUTTON_TYPE.YES_NO == type)
        {
            m_cancel.setVisible(false);
        }
    }

    public void setPresenter(Presenter presenter)
    {
        m_presenter = presenter;
    }

    @UiHandler("m_yes")
    void ok_yes_Click(ClickEvent event)
    {
        if (m_presenter != null)
        {
            m_presenter.yesClick();
        }
    }

    @UiHandler("m_no")
    void no_cancel_Click(ClickEvent event)
    {
        if (m_presenter != null)
        {
            m_presenter.noClick();
        }
    }
    @UiHandler("m_cancel")
    void cancelClick(ClickEvent event)
    {
        if (m_presenter != null)
        {
            m_presenter.cancelClicked();
        }
    }

}
